package com.pingan.haofang.searchcloud.web.monitor.controller;

import com.pingan.haofang.searchcloud.common.configuration.ClusterProperties;
import com.pingan.haofang.searchcloud.common.constants.WebConstants;
import com.pingan.haofang.searchcloud.common.dto.PageDTO;
import com.pingan.haofang.searchcloud.monitor.dto.ChartReportResultDTO;
import com.pingan.haofang.searchcloud.monitor.dto.DashboardResourceInfoQueryDTO;
import com.pingan.haofang.searchcloud.monitor.dto.DashboardResourceInfoResultDTO;
import com.pingan.haofang.searchcloud.monitor.service.DashboardResourceInfoService;
import com.pingan.haofang.searchcloud.web.monitor.form.DashboardResourceInfoQueryByListForm;
import com.pingan.haofang.searchcloud.web.monitor.form.DashboardResourceInfoQueryForm;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author EX-LIUXIANWEN001
 * @date 2018/10/24
 * @since 1.0.0
 */
@RestController
@RequestMapping(WebConstants.WEB_PREFIX + "/dashboardResourceInfo")
@Api(tags = "dashboard.resource", description = "系统资源使用详情")
public class DashboardResourceInfoController {

    @Autowired
    private DashboardResourceInfoService dashboardResourceInfoService;

    @Autowired
    private ClusterProperties clusterProperties;

    @RequestMapping(value = "/viewByList", method = RequestMethod.GET)
    @ApiOperation("硬件视图信息(不分页)")
    public Map<String,List<ChartReportResultDTO>>
            dashboardResourceInfoViewByList(DashboardResourceInfoQueryByListForm form) {
        DashboardResourceInfoQueryDTO dto = new DashboardResourceInfoQueryDTO();
        BeanUtils.copyProperties(form, dto);
        return dashboardResourceInfoService.queryDashboardResourceList(dto);
    }

    @RequestMapping(value = "/view", method = RequestMethod.GET)
    @ApiOperation("硬件列表信息分页")
    public PageDTO<DashboardResourceInfoResultDTO>
            dashboardResourceInfoViewByPage(DashboardResourceInfoQueryForm form) {
        DashboardResourceInfoQueryDTO dto = new DashboardResourceInfoQueryDTO();
        BeanUtils.copyProperties(form, dto);
        return dashboardResourceInfoService.queryDashboardResourceView(dto);
    }

    @RequestMapping(value = "/clusterDict", method = RequestMethod.GET)
    @ApiOperation("获取集群信息字典")
    public List<ClusterProperties.ClusterInfo> getClusterDict() {
        List<ClusterProperties.ClusterInfo> servers = clusterProperties.getServers();
        return servers;
    }
}
